<template>
	<view>
		<jiangyan-calendar ref="jiangyanCalendar" :lastMonth='lastMonth' :nextMonth='nextMonth' :weekText="weekText" @selectedday="selectedday()"></jiangyan-calendar>
		<!-- 没有任何订单图片 -->
		<view id="nodata" v-if="noData == true">
			<image src="../../static/wudingdan.png" mode="aspectFit"></image>
		</view>
		<view class="yhpj" v-else>
			<view class="yhpj-list">
				<view class="item" v-for="(item, index) in courseplan" :key="index">
					<view class="item-right">
						<view class="item-right-top">
							<text>课程类型:{{item.is_course_online==1?'线下课程':'线上课程'}}</text>
							<text>所属机构:{{item.jigou}}</text>
						</view>
						<view class="item-right-bottom">
							<text>课程名称:{{item.coursename}}</text>
							<text>教室:{{item.room}}</text>
							<text>老师:{{item.teacher}}</text>
							<text>上课时间:{{item.starttime}}-{{item.endtime}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
	    
</template>

<script>
	import jiangyanCalendar from "@/components/jiangyan-calendar/jiangyanCalendar.vue";
	import { postMyCoursePlan } from '@/request/courses';
	import {checkUserinfo} from '@/request/checkUserinfo';
	export default {
	    components: {
	        jiangyanCalendar
	    },
	    data() {
	        return {
				lastMonth:'◀',
				nextMonth:'▶',
				//星期数组
				weekText: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
				selectVal: '',
				noData: false,
				courseplan:[]
	        }
	    },
		onShareAppMessage(res) {
			let path = getCurrentPages()
			let path_share = path[0].$page.fullPath
			let path_title = path[0].data.title
			let userinfo = uni.getStorageSync('userinfo')
			let base_set = uni.getStorageSync('base_set')
			if(userinfo.uid=='' || !userinfo.uid){
				uni.navigateTo({
					url:'../login/login'
				})
				return {
					title: '请先登录后再分享给好友',
					path: ''
				}
			}else{
				if (res.from === 'button') {
					
				}
				return {
					title: base_set.title,
					path: `${path_share}?pid=${userinfo.uid}`
				}
			}
		},
		onShow() {
			checkUserinfo()
			this.postMyCoursePlan();
		},
	    methods: {
			//组件监听事件
			selectedday(e) {
				console.log('当前选中日期',e);
				if(e != '' && e != undefined && e){
					if(e != this.selectVal){
						this.selectVal = e;
					}
				}else{
					this.selectVal = uni.getStorageSync('nowdate');
				}
				this.postMyCoursePlan();
			},
			qiehuan(){
			    this.$refs.jiangyanCalendar.switchFg();
			},
			// 获取订单数据
			postMyCoursePlan () {
				let userinfo=uni.getStorageSync('userinfo')
				uni.showLoading({
					title:'正在为您查询...'
				})
				setTimeout(()=>{
					postMyCoursePlan({uid: userinfo.uid,day:this.selectVal}).then(res => {
						console.log(res.data)
						if(!res.data.data) {
							setTimeout(()=>{
								uni.hideLoading();
								uni.showModal({
								    title: '温馨提示',
								    content: res.data.msg,
									showCancel:false,
								    success: function (res) {
								        if (res.confirm) {
								            console.log('用户点击确定');
								        } else if (res.cancel) {
								            console.log('用户点击取消');
								        }
								    }
								});
							},800)
							this.noData = true
					
						} else {
							uni.hideLoading();
							this.noData = false;
							uni.showToast({
								title:'获取课程表成功'
							});
							this.courseplan = res.data.data;
						}
					})
				},1000)
			},
	    }
	}
</script>

<style lang="less" scoped>
	#nodata {
		width: 100%;
		height: 500rpx;
		background-color: #fff;
		image {
			width: 100%;
			height: 100%;
		}
	}
	.yhpj {
		text-align: center;
		margin-bottom: 140upx;
		background-color: #fff;
		padding: 20rpx 0;
		&-list {
			.pingyu{
				width: 100%;
				display: block;
				padding: 10rpx;
				view{
					display: flex;
					flex-direction: column;
					align-items: flex-start;
					text{
						padding: 10rpx;
						font-size: 26rpx;
					}
				}
				
				button{
					margin-top: 10rpx;
				}
			}
			.item {
				display: flex;
				flex-direction: column;
				padding:15upx;
				justify-content: start;
				align-items: center;
				border-top: 1rpx solid #eee;
				border-bottom: 1rpx solid #eee;
				&-left {
					width: 50upx;
					height: 50upx;
					border-radius: 35upx;
					margin-right: 10upx;
				}
				&-right {
					width: 100%;
					display: flex;
					flex-direction: column;
					&-top {
						font-weight: 700;
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding: 10rpx;
						text:nth-child(1) {
							font-size: 28upx;
							color: #333;
						}
						text:nth-child(2) {
							font-size: 26upx;
							color: #999;
						}
					}
					&-bottom {
						max-width: 500upx;
						padding: 15upx 0;
						background-color: #fff;
						display: flex;
						flex-direction: column;
						justify-content: flex-start;
						align-items: flex-start;
						text:first-child{
							font-weight: 700;
						}
						text {
							font-size: 28upx;
							font-weight: 400;
							color: #333;
							padding: 10rpx;
						}
					}
					&-files{
						display: flex;
						align-items: center;
						justify-content: space-around;
						image{
							width: 200upx;
							height: 300upx;
						}
						video{
							width: 300upx;
							height: 200upx;
						}
					}
				}
			}
		}
	}
</style>
